/*
 * Copyright (C) 2016-2018 Samuel Wall
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package uk.co.samuelwall.materialtaptargetprompt;

import ohos.aafwk.ability.fraction.Fraction;
import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.element.Element;
import ohos.app.Context;
import ohos.global.resource.ResourceManager;
import ohos.media.image.PixelMap;

import org.jetbrains.annotations.Nullable;

/**
 * {@link ResourceFinder} implementation for {@link Fraction}.
 *
 * @since 2021-06-01
 */
public class SupportFractionResourceFinder implements ResourceFinder {
    /**
     * The mFraction to get the resources from.
     */
    private final Fraction mFraction;

    /**
     * The mFraction view parent.
     */
    private ComponentContainer mParent;

    /**
     * Constructor.
     *
     * @param fraction Fraction to get the resources from.
     * @param componentContainer componentContainer
     */
    public SupportFractionResourceFinder(final Fraction fraction, ComponentContainer componentContainer) {
        this.mFraction = fraction;
        mParent = componentContainer;

    }

    @Nullable
    @Override
    public Component findViewById(int resId) {
        return this.mFraction.getFractionAbility().findComponentById(resId);
    }

    @Override
    public ComponentContainer getPromptParentView() {
        return mParent;
    }

    @Override
    public Context getContext() {
        return this.mFraction.getFractionAbility();
    }

    @Override
    public ResourceManager getResources() {
        return this.mFraction.getResourceManager();
    }

    @Override
    public String getString(int resId) {
        return this.mFraction.getString(resId);
    }

    @Nullable
    @Override
    public Drawable getDrawable(Element element) {
        Drawable drawable = new Drawable(this.mFraction.getFractionAbility());
        drawable.setImageElement(element);
        return drawable;
    }

    @Nullable
    @Override
    public Drawable getDrawable(PixelMap pixelMap) {
        Drawable drawable = new Drawable(this.mFraction.getFractionAbility());
        drawable.setPixelMap(pixelMap);
        return drawable;
    }
}
